//
//  ViewController.swift
//  Color
//
//  Created by mac on 2018/8/2.
//  Copyright © 2018年 mac. All rights reserved.
//

import UIKit

struct ColorInfo {
    var image:String!
    var title:String!
    var detial:String!
    var date:String!
    
    init(dic:[String:String]) {
        image = dic["image"]
        title = dic["title"]
        detial = dic["detial"]
        date = dic["date"]
    }
}
let rReuseIdentifier:String = "ColorTableViewCellReuseIdentifier"

class ViewController: UITableViewController {
    
    var dataSource:[ColorInfo] {
        get{
            let dPlist:String = Bundle.main.path(forResource: "ColorData", ofType: "plist")!
            
            let dDictionary:NSMutableDictionary = NSMutableDictionary(contentsOfFile:dPlist)!
            
            let dArray:[[String:String]] = dDictionary.object(forKey: "COLORDATA") as! [[String:String]]
            
            var data:[ColorInfo] = []
            
            for obj in dArray {
                data.append(ColorInfo(dic: obj))
            }
            
            return data
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.separatorStyle = .none
        tableView.tableFooterView = UIView()

    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell:ColorTableViewCell = tableView.dequeueReusableCell(withIdentifier: rReuseIdentifier) as! ColorTableViewCell
        cell.setDataModel(dataSource[indexPath.row])
        return cell
    }

}

